package com.yixin.hospital.controller;

import com.yixin.hospital.common.ApiResult;
import com.yixin.hospital.common.Constant;
import com.yixin.hospital.entity.bo.PageInfo;
import com.yixin.hospital.entity.dto.req.returnpaid.ReturnPaidReqDto;
import com.yixin.hospital.entity.vo.ReturnPaidVo;
import com.yixin.hospital.service.ReturnPaidService;
import com.yixin.hospital.utils.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@RequestMapping("/return-paid")
@Api(value = "还款", tags = "还款")
@Slf4j
public class ReturnPaidController {

    @Autowired
    private ReturnPaidService returnPaidService;


    @GetMapping("/list")
    @ApiOperation(value = "获取欠款列表")
    public ApiResult<PageInfo<ReturnPaidVo>> getCurVisitAmount(@RequestParam int currentPage, @RequestParam int pageSize,
                                                               @RequestParam(value = "deptId") Long deptId,
                                                               @RequestParam(value = "workAddressId", required = false) Long workAddressId,
                                                               @RequestParam(value = "jobOfficeId", required = false) Long jobOfficeId,
                                                               @RequestParam(value = "guidanceCode", required = false) String guidanceCode,
                                                               @RequestParam(value = "status", required = false) Integer status) {
        return returnPaidService.getCurVisitAmount(currentPage, pageSize, deptId, workAddressId, jobOfficeId, guidanceCode, status);
    }


    @PostMapping("/returnPaid")
    @ApiOperation(value = "还款操作")
    public ApiResult<?> returnPaid(@Valid @RequestBody ReturnPaidReqDto paidReqDto, HttpServletRequest request) {
        String userName = JwtUtil.getName(request.getHeader(Constant.AUTHORIZATION));
        return returnPaidService.returnPaid(paidReqDto, userName);
    }



}
